﻿using ConsoleApp.enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp.wayline
{
    public class WaylineGenerateParams
    {
        public string waylineName { get; set; }
        public string waylineTempDir { get; set; }
        public string waylineDestDir { get; set; }
        public int templateId { get; set; }
        // 方向: 东西向 true, 南北向 false
        public Boolean direction { get; set; }

        public float interval { get; set; }

        public double boardShortWidth { get; set; }

        public double boardLength { get; set; }

        public double boardAngle { get; set; }

        //    public Double boardRad{ get; set; }

        public double navHeight { get; set; }

        public double boardHeight { get; set; }

        public int drone { get; set; }
        public int droneSub { get; set; }
        public int payload { get; set; }
        public int payloadSub { get; set; }
        public int payloadIndex { get; set; }

        public float takeOffSecurityHeight { get; set; }

        public float flightSpeed { get; set; }

        public float globalRTHHeight { get; set; }

        // public List<GeoPoint2D> point2DS{ get; set; }
        public List<object> point2DS { get; set; }

        public string imageFormat { get; set; }

        /**   */
        public string heightMode { get; set; }
        public string executeHeightMode { get; set; }

        public MissionConfigParam missionConfig { get; set; } = new MissionConfigParam();
        public WaypointFloderParam floderParam { get; set; } = new WaypointFloderParam();
    }



    #region 数据模型类
    /// <summary>
    /// 任务配置信息
    /// </summary>
    public class MissionConfigParam
    {
        // 飞向首航点模式
        public string FlyToWaylineMode { get; set; } = FlyToWaylineModeEnums.Safely.GetValue();
        public string FinishAction { get; set; } = FinishActionEnums.GoHome.GetValue();
        public string ExitOnRCLost { get; set; } = ExitOnRCLostEnums.ExecuteLostAction.GetValue();
        public string ExecuteRCLostAction { get; set; } = ExecuteRCLostActiontEnums.GoBack.GetValue();
        public float TakeOffSecurityHeight { get; set; } = 45F;
        public float GlobalRTHHeight { get; set; } = 80F;
        // 参考起飞点 非必须元素
        public string TakeOffRefPoint { get; set; }
        // 参考起飞点海拔高度 非必须元素
        public int TakeOffRefPointAGLHeight { get; set; }
        public float GlobalTransitionalSpeed { get; set; } = 7F;
        public int DroneEnumValue { get; set; } = DeviceModels.M350.Type.ToInt(); // M350
        public int DroneSubEnumValue { get; set; } = DeviceModels.M350.SubType.ToInt(); // M350
        public int PayloadEnumValue { get; set; } = PayloadDeviceModels.H20T.Type.ToInt(); // H20T payload
        public int PayloadSubEnumValue { get; set; } = PayloadDeviceModels.H20T.SubType.ToInt(); // H20T payload
        public int PayloadPositionIndex { get; set; } = PayloadDeviceModels.H20T.Gimbalindex;
    }
    /// <summary>
    /// 航点文件夹
    /// </summary>
    public class WaypointFloderParam
    {
        public string templateType { get; set; } = FolderTemplateTypeEnums.Waypoint.GetValue();
        public int templateId { get; set; } = 0;
        public int waylineId { get; set; } = 0;
        public string executeHeightMode { get; set; } = ExecuteHeightModeEnums.RelativeToStartPoint.GetValue();
        public WaylineCoordinateSysParam waylineCoordinateSysParam { get; set; }
        public float autoFlightSpeed { get; set; } = 7F;
        // 全局航线高度（相对起飞点高度）
        public float globalHeight { get; set; } = 45F;
        public string gimbalPitchMode { get; set; } = GimbalPitchModeEnums.UsePointSetting.GetValue();
        public string globalWaypointTurnMode { get; set; } = WaypointTurnModeEnums.ToPointAndPassWithContinuityCurvature.GetValue();

        // 全局航段轨迹是否尽量贴合直线
        // 必需元素
        // * 注：当且仅当“wpml:globalWaypointTurnMode”被设置为“toPointAndStopWithContinuityCurvature”或“toPointAndPassWithContinuityCurvature”时必需。
        // 如果额外定义了某航点的该元素，则局部定义会覆盖全局定义。
        // 0：航段轨迹全程为曲线
        // 1：航段轨迹尽量贴合两点连线
        public int globalUseStraightLine { get; set; } = 1;

        public WaypointHeadingParam globalWaypointHeadingParam { get; set; } = new WaypointHeadingParam();

        public PayloadParam payloadParam { get; set; } = new PayloadParam();

        public List<Placemark> placemarks = new List<Placemark>();

    }
    public class PayloadParam
    {
        public int payloadPositionIndex { get; set; } = 0;
        public string focusMode { get; set; } = FocusModeEnums.FirstPoint.GetValue();
        public string meteringMode { get; set; } = MeteringModeEnums.Average.GetValue();
        // 是否开启畸变矫正: 0：不开启, 1：开启
        public int dewarpingEnable { get; set; } = 1;
        public string returnMode { get; set; } = ReturnModeEnums.DualReturn.GetValue();
        public float samplingRate { get; set; } = 240000F;
        // 真彩上色 0: 不上色, 1: 真彩上色
        public int modelColoringEnable { get; set; } = 1;
        public string scanningMode { get; set; } = ScanningModeEnums.Repetitive.GetValue();
        // visable：可见光照片
        public string imageFormat { get; set; } = "zoom,ir";
    }

    public class Placemark
    {
        // 是否开启标定飞行 * 注：仅适用于M300 RTK与M350 RTK机型
        // 0：不开启 1：开启，航线中自动进行惯导标定，保证模型精度。
        // 航线收尾会进行三次加减速飞行，航线拐弯处自动外扩进行加减速飞行。
        // 航线过长会均匀插入加减速飞行，每次标定后飞行时间不会超过100s。
        public int caliFlightEnable { get; set; } = 0;
        public string pointCoordinates { get; set; }
        public int index { get; set; }
        public int useStraightLine { get; set; } = 1;
        public float ellipsoidHeight { get; set; }
        public float height { get; set; }
        public float executeHeight { get; set; }
        public float waypointSpeed { get; set; } = 7F;
        public int useGlobalHeight { get; set; } = 1;
        public int useGlobalSpeed { get; set; } = 1;
        public int useGlobalHeadingParam { get; set; } = 1;
        public int useGlobalTurnParam { get; set; } = 1;
        public float gimbalPitchAngle { get; set; } = -90F;

        public WaypointHeadingParam waypointHeadingParam { get; set; } = new WaypointHeadingParam();
        public WaypointTurnParam waypointTurnParam { get; set; } = new WaypointTurnParam();
        public ActionGroup actionGroup { get; set; } = new ActionGroup();
    }
    public class WaypointTurnParam
    {
        public string waypointTurnMode { get; set; } = WaypointTurnModeEnums.ToPointAndPassWithContinuityCurvature.GetValue();
        public float waypointTurnDampingDist { get; set; } = 0.2F;
    }
    public class WaypointHeadingParam
    {
        public string waypointHeadingMode { get; set; } = WaypointHeadingModeEnums.SmoothTransition.GetValue();
        public float waypointHeadingAngle { get; set; } = 0F;
        public string waypointPoiPoint { get; set; }
        public string waypointHeadingPathMode { get; set; } = WaypointHeadingPathModeEnums.Clockwise.GetValue();
        public int waypointHeadingAngleEnable { get; set; } = 1;

    }
    /// <summary>
    /// 航点坐标系统参数
    /// </summary>
    public class WaylineCoordinateSysParam
    {
        public string CoordinateMode { get; set; } = "WGS84";
        public string HeightMode { get; set; } = HeightModeEnums.EGM96.GetValue();
        
        // 经纬度与高度数据源 非必须元素
        public string PositioningType { get; set; } = "GPS";
        // 飞行器离被摄面高度（相对地面高）* 注：仅适用于模板类型mapping2d，mapping3d，mappingStrip
        public float GlobalShootHeight { get; set; } = 60F;
        // 是否开启仿地飞行 * 注：仅适用于模板类型mapping2d，mapping3d，mappingStrip
        public bool SurfaceFollowModeEnable { get; set; } = true;
        // 仿地飞行离地高度（相对地面高）* 注：仅适用于模板类型mapping2d，mapping3d，mappingStrip
        public float SurfaceRelativeHeight { get; set; } = 60F;
    }

    /// <summary>
    /// 航点朝向参数
    /// </summary>
    //public class WaypointHeadingParam
    //{
    //    public string HeadingMode { get; set; } = "followWayline";
    //    public double HeadingAngle { get; set; } = 45;
    //    public string PoiPoint { get; set; } = "24.323345,116.324532,31.000000";
    //    public string HeadingPathMode { get; set; } = "clockwise";
    //}

    /// <summary>
    /// 航点信息
    /// </summary>
    public class Waypoint
    {
        public int Index { get; set; }
        public double Longitude { get; set; }
        public double Latitude { get; set; }
        public double Altitude { get; set; }
        public double EllipsoidHeight { get; set; } = 90.2;
        public int Height { get; set; } = 100;
        public bool UseGlobalHeight { get; set; } = true;
        public bool UseGlobalSpeed { get; set; } = true;
        public bool UseGlobalHeadingParam { get; set; } = true;
        public bool UseGlobalTurnParam { get; set; } = true;
        public double GimbalPitchAngle { get; set; } = 0;
        public ActionGroup ActionGroup { get; set; }
    }

    /// <summary>
    /// 动作组
    /// </summary>
    public class ActionGroup
    {
        public int actionGroupId { get; set; }
        public int actionGroupStartIndex { get; set; }
        public int actionGroupEndIndex { get; set; }
        public string actionGroupMode { get; set; } = "sequence";
        public string actionTriggerType { get; set; } = ActionTriggerTypeEnums.ReachPoint.GetValue();
        public List<Action> actions { get; set; } = new List<Action>();
    }

    /// <summary>
    /// 动作信息
    /// </summary>
    public class Action
    {
        public int actionId { get; set; }
        public string actionActuatorFunc { get; set; }
        public Dictionary<string, string> actionActuatorFuncParams { get; set; } = new Dictionary<string, string>();
    }
    #endregion

}
